package com.fh.controller;/**
 * 描述:
 * Author:袁亚强
 * Date:2021/11/2511:38
 */

import com.fh.common.yyqData;
import com.fh.entity.po.Shop;
import com.fh.entity.vo.Result;
import com.fh.entity.vo.ShopVo;
import com.fh.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * created by macro on 2021/11/25,
 */
@RestController
@RequestMapping("shop")
public class ShopController {
    @Autowired
    private ShopService shopService;

    @GetMapping("queryById")
    public yyqData queryById(Integer id){
        if (id==null){
            return yyqData.error(400, "缺少参数");
        }
        return yyqData.success(shopService.queryById(id));
    }
    @PostMapping("upShop")
    public yyqData upShop(Shop shop){
        if (shop.getId()==null){
            return yyqData.error(400, "缺少参数");
        }
        shopService.upShop(shop);
        return yyqData.success("");
    }

    @PostMapping("addShop")
    public  yyqData addShop(Shop shop){
        shopService.addShop(shop);
        return yyqData.success("");
    }

    //根据分类id 查询 key value表 sku和非sku数据
    @GetMapping("queryIsSkuData")
    public yyqData queryIsSkuData(Integer id){
        if (id==null){
             return yyqData.error(400, "缺少参数");
        }
        return yyqData.success(shopService.queryIsSkuData(id));
    }


    @PostMapping("addShops")
    public yyqData addShops(Shop shop){
        shopService.addShops(shop);
        return yyqData.success("");
    }


    @GetMapping("queryPageData")
    public yyqData queryPageData(ShopVo shopVo){
        if(StringUtils.isEmpty(shopVo.getPage())||StringUtils.isEmpty(shopVo.getSize())){
            return yyqData.error(400, "缺少参数");
        }
        return yyqData.success(shopService.queryPageData(shopVo));
    }


    @PostMapping("queryImgsById")
    public yyqData queryImgsById(Integer id){
        if (id==null){
            return yyqData.error(400, "缺少参数");
        }
        return yyqData.success(shopService.queryImgsById(id));
    }



    @PostMapping("addShopImgs")
    public yyqData addShopImgs(Integer pid,String imgsList){
        shopService.addShopImgs(pid,imgsList);
        return yyqData.success("");
    }

    @PostMapping("delImgs")
    public yyqData delImgs(Integer id){
        if (id==null){
            return yyqData.error(400, "缺少参数");
        }
        shopService.delImgs(id);
        return yyqData.success("");
    }

    @PostMapping("queryShopValuesById")
    public yyqData queryShopValuesById(Integer id){
        if (id==null){
            return yyqData.error(400, "缺少参数");
        }
        return yyqData.success(shopService.queryShopValuesById(id));
    }


    @RequestMapping("queyrValuesByPid")
    public yyqData queyrValuesByPid(Integer id){
        return yyqData.success(shopService.queryShopValuesByPid(id));
    }

    @PostMapping("deleteShopValues")
    public yyqData deleteShopValues(Integer pid){
        shopService.deleteShopValues(pid);
        return yyqData.success("");
    }
    @PostMapping("upValues")
    public yyqData upValues(Integer pid,String valuess){
        if (pid==null){
            return yyqData.error(400, "缺少参数");
        }
        shopService.upValues(pid,valuess);
        return yyqData.success("");
    }


}
